<?php

namespace App\Jobs\PiaoChi\Order;

use App\Trip\Train\Providers\PiaoChi\Callback\OrderNotify;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class ProcessOrderNotify implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private OrderNotify $notify;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(OrderNotify $notify)
    {
        $this->notify = $notify;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws Exception
     */
    public function handle()
    {
        $this->notify->dealOrdersNotify();
    }


    /**
     * 任务的唯一 ID。
     *
     * @return
     */
    public function uniqueId()
    {
        return $this->notify->getOrderId();
    }

    public function failed()
    {
        $order_id = $this->notify->getOrderId();
        Log::error("ProcessOrderNotify:火车票回调业务处理失败,outOrderId = {$order_id}");
    }

    /**
     * 计算重试任务之前要等待的秒数。
     *
     * @return array
     */
    public function backoff()
    {
        return [5, 30, 60];
    }
}
